/**
 *    <JPanel TextPanel>
 *   Copyright (C) 2011  Fernando Gil
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *   The following additional terms will apply to the software provieded with
 *   this file.
 *      1. Preserve the original authors’ names.
 *      2. Documenting all contributions and specify the contributor's name,
 *         the date of the contribution and some email to future contact.
 *
 *   @author  Fernando Gil
 *   @mail    lobho.gil@gmail.com
 *   @company Development Solutions (DS) Software
 *   @date    10-09-2011
 *   @modify  15-09-2011
 *   @by      Fernando Gil
 *   @see     License GNU GPL v3  (/doc/GNU_GPLv3_EN)
 *   @see     Additional Terms    Point 7.1 on License (/doc/GNU_GPLv3_EN)
 *   @note   Replicate this header in all classes.
 *
 */

package org.dss.gil.view;

import org.dss.gil.interfaces.GenericFileInterface;



public class TextPanel extends javax.swing.JPanel implements GenericFileInterface{


    /** Creates new form TextPanel */
    public TextPanel() {
        initComponents();
    }

    public void setText(String text){
        this.jTextPane1.setText(text);
    }

    public String getText() {
        return this.jTextPane1.getText();
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();

        jTextPane1.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N
        jTextPane1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextPane1KeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTextPane1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    //KeyChar
    private final int GENERIC_CODE = 65535;
    private void jTextPane1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextPane1KeyPressed
        if ((int)evt.getKeyChar()  != GENERIC_CODE   )
            this.setSaved(false);
    }//GEN-LAST:event_jTextPane1KeyPressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables


    /*********************************************************************
     ******************* FROM SAVED INTERFACE ****************************
     *********************************************************************/


    private boolean boo_saved;
    private boolean boo_new;
    private String  str_fileName;
    private String  str_path;

    /** Return true if the file is already saved*/
    public boolean isSaved() {
        if(this.jTextPane1.getText().trim().isEmpty() && this.isNew())
            return true;
        else
            return this.boo_saved;
    }

    public void setFileName(String name) {
        this.str_fileName = name;
    }

    public void setSaved(boolean saved) {
        this.boo_saved = saved;
    }

    public String getFileName() {
        return this.str_fileName;
    }

    public void setPath(String path) {
        this.str_path = path;
    }

    public String getAbsolutePath() {
        return this.str_path+this.str_fileName;
    }

    public String getPath() {
        return this.str_path;
    }

    public void setNew(boolean isNew) {
        this.boo_new = isNew;
    }

    public boolean isNew() {
        return this.boo_new;
    }



}
